import {request } from 'ice';
import {API_URL} from './ApiUrl';
import {Message} from '@alifd/next';

/**
 * 轮播图-列表接口
 * @param {*} params 
 */
async function listPage(params) {
    try {
        const response = await request.post(API_URL.API_ROTATION_IMAGES_LIST, params);
        if(response.status == 0){
          return response.data;
        }else{
          const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
          Message.error(msg)
        }
    } catch (error) {
      console.error(error);
    }
}

/**
 * 查询轮播图-详情
 * @param {*} params 
 */
async function detail(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_DETAIL, {id: params});
      if(response.status == 0){
        return response.data;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
      }
  } catch (error) {
    console.error(error);
  }
}
async function detailV(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_DETAIL_V, {id: params});
      if(response.status == 0){
        return response.data;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
      }
  } catch (error) {
    console.error(error);
  }
}
/**
 * 新增轮播图-
 * @param {*} params 
 */
async function add(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_ADD, params);
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}

/**
 * 修改轮播图-信息
 * @param {*} params 
 */
async function update(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_UPDATE, params);
      if(response.status == 0){
        return true;
      }else if(response.status == 41501){
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }else {
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}

/**
 * 删除轮播图-
 * @param {*} params 
 */
async function deleteRotationImage(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_DELETE, {id: params});
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}

/**
 * 发布轮播图-
 * @param {*} params 
 */
async function publish(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_PUBLISH, {id: params});
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}
/**
 * 下架轮播图-
 * @param {*} params 
 */
async function downShelf(params) {
  try {
      const response = await request.post(API_URL.API_ROTATION_IMAGES_DOWN_SHELF, {id: params});
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}
export {listPage, detail, detailV, add, update, deleteRotationImage, publish, downShelf}